package com.zmm.weblog.admin.controller;

import com.zmm.weblog.admin.model.vo.article.*;
import com.zmm.weblog.admin.service.AdminArticleService;
import com.zmm.weblog.common.aspect.ApiOperationLog;
import com.zmm.weblog.common.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * @Author: 福禄寿
 * @Date: 2024/5/14 下午5:05
 * @Des: weblog-springboot
 **/

@RestController
@RequestMapping("/admin/article")
@Api(tags = "Admin 文章模块")
public class AdminArticleController {

    @Autowired
    private AdminArticleService articleService;

    @PostMapping("/publish")
    @ApiOperation(value = "文章发布")
    @ApiOperationLog(description = "文章发布")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response publishArticle(@RequestBody @Validated PublishArticleReqVo publishArticleReqVo) {
        return articleService.publishArticle(publishArticleReqVo);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "文章删除")
    @ApiOperationLog(description = "文章删除")
    public Response deleteArticle(@RequestBody @Valid DeleteArticleReqVO deleteArticleReqVO) {
        return articleService.deleteArticle(deleteArticleReqVO.getId());
    }

    @PostMapping("/list")
    @ApiOperation(value = "查询文章分页数据")
    @ApiOperationLog(description = "查询文章分页数据")
    public Response findArticlePageList(@RequestBody @Valid FindArticlePageListReqVo findArticlePageListReqVo) {
        return articleService.findArticlePageList(findArticlePageListReqVo);
    }

    @PostMapping("/detail")
    @ApiOperation(value = "查询文章详情")
    @ApiOperationLog(description = "查询文章详情")
    public Response detailArticle(@RequestBody @Valid FindArticleDetailReqVo findArticleDetailReqVo) {
        return articleService.detailArticle(findArticleDetailReqVo);
    }

    @PostMapping("/update")
    @ApiOperation(value = "文章更新")
    @ApiOperationLog(description = "文章更新")
    public Response updateArticle(@RequestBody @Valid updateArticleReqVo updateArticleReqVo) {
        return articleService.updateArticle(updateArticleReqVo);
    }

}